package cn.cmeizu.spring6.autowired.controller;

import cn.cmeizu.spring6.autowired.service.UserService;
import org.springframework.stereotype.Controller;

/**
 * @author cmeizu
 * @date 2023/2/9 22:58
 */
@Controller
public class UserController {

  /**
   * set方法注入
   *
   * @param userService
   */
  //@Autowired
  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  /**
   * 构造方法上注入
   *
   * @param userService
   */
  //@Autowired
  //public UserController(UserService userService) {
  //  this.userService = userService;
  //}

  /**
   * 形参上注入
   *
   * @param userService
   */
  //public UserController(@Autowired UserService userService) {
  //  this.userService = userService;
  //}


  /**
   * 只有一个有参构造可以不加注解
   *
   * @param userService
   */
  public UserController(UserService userService) {
    this.userService = userService;
  }

  /**
   * 定义service属性
   */
  //@Autowired
  private UserService userService;


  public void testController() {
    System.out.println("执行controller的方法");
    userService.addUserService();
  }
}
